package com.qzuser.sendmessagebasic.server.message;

import java.io.Serial;
import java.io.Serializable;
import java.util.Arrays;
import java.util.UUID;

public class Message implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;
    private BasicProperties properties = new BasicProperties();
    private byte[] body;
    private transient Long offsetBeg = 0L;
    private transient Long offsetEnd = 0L;
    private Byte isValid = 0x1;

    public static Message createMessageWithId(BasicProperties properties, String routingKey, byte[] body) {
        Message message = new Message();
        if (properties != null) {
            message.setProperties(properties);
        }
        message.setMessageId("M-" + UUID.randomUUID());
        message.setRoutingKey(routingKey);
        message.setBody(body);
        return message;
    }

    public String getMessageId() {
        return properties.getMessageId();
    }

    public void setMessageId(String messageId) {
        properties.setMessageId(messageId);
    }

    public String getRoutingKey() {
        return properties.getRoutingKey();
    }

    public void setRoutingKey(String routingKey) {
        properties.setRoutingKey(routingKey);
    }

    public Integer getDeliverMode() {
        return properties.getDeliverMode();
    }

    public void setDeliverMode(Integer deliverMode) {
        properties.setDeliverMode(deliverMode);
    }

    public BasicProperties getProperties() {
        return properties;
    }

    public void setProperties(BasicProperties properties) {
        this.properties = properties;
    }

    public byte[] getBody() {
        return body;
    }

    public void setBody(byte[] body) {
        this.body = body;
    }

    public Long getOffsetBeg() {
        return offsetBeg;
    }

    public void setOffsetBeg(Long offsetBeg) {
        this.offsetBeg = offsetBeg;
    }

    public Long getOffsetEnd() {
        return offsetEnd;
    }

    public void setOffsetEnd(Long offsetEnd) {
        this.offsetEnd = offsetEnd;
    }

    public Byte getIsValid() {
        return isValid;
    }

    public void setIsValid(Byte isValid) {
        this.isValid = isValid;
    }

    @Override
    public String toString() {
        return "message: {" + "\n\t" +
                    "BasicProperties: {" + "\n\t\t" +
                        "messageId:" + properties.getMessageId() + ",\n\t\t" +
                        "routingKey:" + properties.getRoutingKey() + ",\n\t\t" +
                        "deliverMode:" + properties.getDeliverMode() + "\n\t" +
                    "}\n\t" +
                    "body: " + new String(body) + ",\n\t" +
                    "offsetBeg: " + offsetBeg + ",\n\t" +
                    "offsetEnd: " + offsetEnd + ",\n\t" +
                    "isValid: " + isValid + "\n" +
                '}';
    }
}
